<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\common\model;

/**
 * 赌王模型
 */
class GamblerKingInvestmentUserLog extends ModelBase
{
    protected $insert = ['create_time'];


    /**
     * 时间自动完成
     */
    public function setCreateTimeAttr()
    {

        return TIME_NOW;
    }


    /**
     * 连用户表
     */
    public function user(){
        return $this->belongsTo('Member','user_id','id');
    }

    /**
     * 连产品分类表
     */
    public function investment(){
        return $this->belongsTo('GamblerKingInvestment','investment_id','id');
    }

    /**
     * 总委托人数
     *
     */
    public function getOrderCountAttr(){
        return $this->investment()->where(['user_investment_id'=>$this->user_investment_id,'create_time'=>['between',[$this->start_time,$this->expire_time]]])->count();
    }

    /**
     * 总委托金额
     *
     */
    public function getOrderTotalAttr(){
        return $this->investment()->where(['user_investment_id'=>$this->user_investment_id,'create_time'=>['between',[$this->start_time,$this->expire_time]]])->sum('money')+0;
    }



    /**
     * 连赌王表
     */
    public function king(){
        return $this->belongsTo('GamblerKing','king_id','id');
    }

    public function geStartTimeAttr($value){

        return date('Y-m-d H:i:s',$value);
    }

    public function geExpireTimeAttr($value){

        return date('Y-m-d H:i:s',$value);
    }



}
